
<div class="layui-fluid" style="padding: 15px">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    人员信息
                </div>
                <div class="layui-card-body">
                    <table id="staff" lay-filter="testStaff"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--角色工具栏-->
<script type="text/html" id="toolbarStaff">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="addMenutble">添加角色</button>
    </div>
</script>
<!--右边工具栏-->
<script type="text/html" id="barDemoStaff">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use('table', function(){
        var  $ = layui.$
            ,table = layui.table;


        //菜单表格
        table.render({
            elem: '#staff'
            ,height: 500
            ,id:'table'
            ,url: '../../Staff' //数据接口
            ,toolbar: '#toolbarStaff' //开启头部工具栏，并为其绑定左侧模板
            ,limit:5
            ,limits:[5,10,15,20]
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_menu'
                ,icon: 'layui-icon-tips'
            }]
            ,page: true //开启分页
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'personnelId', title: '人员信息id', sort: true}
                ,{field: 'tmsName', title: '用户姓名',templet:function(res){
                            return res.tmsUser.tmsName;
                        }}
                ,{field: 'account', title: '用户账号',templet:function(res){
                        return res.tmsUser.account;
                    }}
                ,{field: 'phonenumber', title: '个人手机号',templet:function(res){
                        return res.tmsUser.phonenumber;
                    }}
                ,{field: 'education', title: '学历'}
                ,{field: 'site', title: '员工地址'}
                ,{field: 'sex', title: '性别',width: 60}
                ,{field: 'salary', title: '薪资'}
                ,{field: 'hiredate', title: '入职时间'}
                ,{field: 'tmsPassword', title: '生日',hide:true,templet:function(res){
                        return res.tmsUser.tmsPassword;
                    }}
                ,{field: 'tmsId', title: '生日',hide:true,templet:function(res){
                        return res.tmsUser.tmsId;
                    }}
                ,{field: 'identitycard', title: '生日',hide:true}
                ,{field: 'hometelephone', title: '生日',hide:true}
                ,{field: 'subid', title: '生日',hide:true}
                ,{field: 'birthday', title: '生日'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemoStaff'}
            ]]
        });
        //角色头部工具栏头工具栏事件
        table.on('toolbar(testStaff)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'addMenutble':
                    //添加用户信息
                    show="添加"
                    //iframe层
                    layer.open({
                        type: 2,
                        title: show+'员工',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['1000px', '90%'],
                        content: '../src/views/system/iframe/addTmsUser.html' //iframe的url
                    });
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_user':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });
        //监听用户行工具事件
        table.on('tool(testStaff)', function(obj){
            var data = obj.data;

            /*删除*/
            if(obj.event === 'del'){
                alert(data.personnelId)
                $.ajax({
                    type: "POST",
                    url:  '../../deletePersonnerByid?id='+data.personnelId,
                    dataType: "text",
                    success: function(data){
                        table.reload('table');
                    }
                });
            } else if(obj.event === 'edit'){
                //修改
                layer.open({
                    type: 2,
                    shadeClose: true,
                    shade: 0.8,
                    area: ['1000px', '90%'],
                    content: '../src/views/system/iframe/updateTmsUser.html' //iframe的url,
                    ,success: function(layero, index){
                        data=obj.data;
                        alert(data.subid)
                        var body = layer.getChildFrame('body', index);
                        body.find('#personnelId').val(data.personnelId);
                        body.find('#tmsName').val(data.tmsUser.tmsName);
                        body.find('#account').val(data.tmsUser.account);
                        body.find('#phonenumber').val(data.tmsUser.phonenumber);
                        body.find('#hometelephone').val(data.clientgrade);
                        body.find('#education').val(data.education);
                        body.find('#site').val(data.site);
                        body.find('#sex').val(data.sex);
                        body.find('#salary').val(data.salary);
                        body.find('#hiredate').val(data.hiredate);
                        body.find('#birthday').val(data.birthday);
                        body.find("#tmsPassword").val(data.tmsUser.tmsPassword)
                        body.find("#identitycard").val(data.identitycard)
                        body.find("#hometelephone").val(data.hometelephone)
                        body.find("#personnelId").val(data.personnelId)
                        body.find("#tmsId").val(data.tmsUser.tmsId)
                    }
                });
            }
        });

    });
</script>